package com.itheima.health.dao;

import com.github.pagehelper.Page;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Setmeal;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author hm
 * @version 1.0
 * @date Created in 2024/7/13 17:30
 */
public interface CheckGroupDao {
    Page<CheckGroup> findPage(String queryString);
    @Select("select * from t_checkgroup where id = #{id}")
    CheckGroup findById(Integer id);
    @Select("select checkitem_id from t_checkgroup_checkitem where checkgroup_id = #{checkGroupId}")
    List<Integer> findCheckItemIds(Integer checkGroupId);
    @Select("select * from t_checkitem")
    List<CheckItem> findAll();

    void update(CheckGroup checkGroup);
    @Delete("delete from t_checkgroup_checkitem where checkgroup_id = #{checkgroup_id};")
    void deleteAssociation(Integer id);
    @Insert("insert into t_checkgroup  values (null,#{code}, #{name}, #{helpCode}, #{sex}, #{remark}, #{attention});")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void add(CheckGroup checkGroup);

    void addCheckItem(Integer id,Integer[] ids);
    @Delete("delete from t_checkgroup where id = #{checkGroupId}")
    void delete(Integer checkGroupId);
    @Select("select * from t_checkgroup where id in (select checkgroup_id from t_setmeal_checkgroup where setmeal_id = #{id})")
    List<CheckGroup> findBySetmealId(Integer id);
    @Select("select * from t_checkgroup")
    List<CheckGroup> find();
    @Select("select setmeal_id from t_setmeal_checkgroup where checkgroup_id=#{checkGroupId}")
    List<Integer> findSetmeal(Integer checkGroupId);
}
